package com.lld.crowdfunding.config;

<<<<<<< HEAD
=======
import com.lld.crowdfunding.handler.AuthorityIntercepter;
>>>>>>> 42dbb3a (20210806)
import com.lld.crowdfunding.handler.RemeberLoginIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private RemeberLoginIntercepter remeberLoginIntercepter;

<<<<<<< HEAD
    /*添加登录拦截器*/
    @Override
    public void addInterceptors(InterceptorRegistry registry) {


        /*registry.addInterceptor(new HandlerInterceptor() {
            @Override
            public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
                HttpSession session = request.getSession();
                User user = (User) session.getAttribute("user");
                if(user != null) {
                    return true;
                }else {
                    response.sendRedirect("/login.html");//控制器路径
                    return false;
                }
            }
        }).addPathPatterns("/**").excludePathPatterns("/webjars/**",
                "/v2/**","/swagger-resources/**","/swagger-ui.html",
                "/login.html","/","/css/**","/fonts/**","/images/**",
                "/js/**","/user/doLogin.html");*/

=======
    @Autowired
    private AuthorityIntercepter authorityIntercepter;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        /*添加登录拦截器*/
>>>>>>> 42dbb3a (20210806)
        registry.addInterceptor(remeberLoginIntercepter)
                .addPathPatterns("/**")
                .excludePathPatterns("/webjars/**",
                        "/v2/**","/swagger-resources/**","/swagger-ui.html",
                        "/css/**","/fonts/**","/images/**",
<<<<<<< HEAD
                        "/js/**","/user/doLogin.html","/login.html","/logout.html");
=======
                        "/js/**","/user/doLogin.html","/login.html","/user/logout.html");

        /*添加权限拦截器*/
        registry.addInterceptor(authorityIntercepter)
                .addPathPatterns("/user/**","/userManager.html","/orderManager.html")
                .excludePathPatterns("/user/logout.html","/user/doLogin.html");
>>>>>>> 42dbb3a (20210806)
    }
}
